package com.nlp.cahe;

public class LRUCacheFactory {
	
	private LRUCache<String,CacheEntry> cache;
	
	private LRUCacheFactory() {
		cache = new LRUCache<String, CacheEntry>(10);
	}
	
	private static class Holder{
		private static final LRUCacheFactory FACTORY = new LRUCacheFactory();
	}
	
	public static LRUCacheFactory getFactory() {
		return Holder.FACTORY;
	}
	public String getValue(String key) {
		CacheEntry entry = cache.get(key);
		if (entry == null) {
			return null;
		}
		long d = entry.timeout;
		long now = System.currentTimeMillis();
		if (now > d) {
			cache.remove(key);
			return null;
		}
		return new String(entry.data);
	}
	
	public void put(String key, String value,long timeout) {
		timeout = System.currentTimeMillis()+timeout;
		CacheEntry entry = new CacheEntry(timeout, value.getBytes());
		this.cache.put(key,entry);
	}
	
	public static void main(String[] args) {}

}
